<?php
/**
 * Created by PhpStorm.
 * User: zing
 * Date: 2018/5/5
 * Time: 9:26
 */


$all_lists = [];
$calc_time = [];
$index = 0;
$_for_i = 0;
$_fun_i = 0;
while ($index < 1000) {
    $length = 10 * $index;
    for ($i = 0; $i < $length; $i++) {
        $all_lists[$i] = ['supplier_ticket_id' => 11, 'biz_ticket_id' => 114, 'buy_num' => 1, 'ticket_sale_price' => 100 * (1 + $i % 3)];//100
    }
    printf("数组长度为 %d\n", $length);
    $start = microtime(true);
    $sum = array_sum(array_column($all_lists, 'ticket_sale_price'));
    $end = microtime(true);
    $_fun = $end - $start;
    printf("函数 -> 消耗时间 %f, 和 %d \n", $_fun, $sum);

    $target_calc_price = 0.00;
    $start = microtime(true);
    foreach ($all_lists as $all_lists_val) {
        $target_calc_price += $all_lists_val['ticket_sale_price'];
    }
    $end = microtime(true);
    $_for = $end - $start;
    $calc_time[1][] = $end - $start;
    printf("循环 -> 消耗时间 %f, 和 %d\n", $_for, $target_calc_price);
    printf("---------------------------------------------------------------\n");
    if ($_for > $_fun) {//for用时间长，则fun+1
        $_fun_i++;
    } else {//fun用时间长，则for+1
        $_for_i++;
    }
    $index++;
}
printf("%d\n", $_for_i + $_fun_i);
printf("fun %f\n", $_fun_i / ($_fun_i + $_for_i));
printf("for %f\n", $_for_i / ($_fun_i + $_for_i));